/// 数组
// 反转数组
type ReverseArr<Arr extends unknown[]> = Arr extends [...infer Reset, infer last]
? [last, ...ReverseArr<Reset>]
: Arr

type ReverseArrRes = ReverseArr<[1,2,3,4]>

// 判断两个类型是否相同
type IsEqual<A, B> = (A extends B ? true : false) & (B extends A ? true : false);

// 查找数组是否存在某个值
type Includes<Arr extends unknown[], FindItem> = Arr extends [infer Left, ...infer Reset]
? IsEqual<Left, FindItem> extends true ? true : Includes<Reset, FindItem>
: false

// 排除数组某个值
type RemoveItem<
    Arr extends unknown[], 
    Item, 
    Result extends unknown[] = []
> = Arr extends [infer First, ...infer Rest]
        ? IsEqual<First, Item> extends true
            ? RemoveItem<Rest, Item, Result>
            : RemoveItem<Rest, Item, [...Result, First]>
        : Result;
type RemoveItemRes = RemoveItem<[1,2,2,3], 2>

// 构造指定长度的数组
type BuildArray<
    Length extends number, 
    Ele = unknown, 
    Arr extends unknown[] = []
> = Arr['length'] extends Length 
        ? Arr 
        : BuildArray<Length, Ele, [...Arr, Ele]>;
type BuildArrayRes = BuildArray<5>

// 深度对象可读
type DeepReadonly<Obj extends Record<string, any>> = {
  readonly [key in keyof Obj]: 
    Obj[key] extends Object
    ? Obj[key] extends Function
      ? Obj[key]
      : DeepReadonly<Obj[key]>
    : Obj[key]
}

type DeepReadonlyRes = DeepReadonly<{name: {sex: 1}}>
const deepReadonlyRes: DeepReadonlyRes = {
  name: {
    sex: 1
  }
}